package com.houg.testuserapi.configuration;

import com.houg.testuserapi.common.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

/**
 * @Author: NALHOUG
 * @Time: 2019/11/8 14:49
 * @Explain: 配置拦截器
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport {
    @Resource
    private LoginInterceptor loginInterceptor;

    /**
     * 具体配置
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                //addPathPatterns 用于添加拦截规则
                .addPathPatterns("/**")
                .excludePathPatterns("/")
                //用户登录
                .excludePathPatterns("/login")
                //用户注册
                .excludePathPatterns("/register/**")
                //开放测试
                .excludePathPatterns("/test/**");
        super.addInterceptors(registry);
    }

}
